﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DormMS.IService;
using DormMS.Model.SearchModels;
using DormMS.Model.ViewModels;

namespace DormMS.Controllers
{
    public class FreightController : BaseController
    {
        protected IFreightService freightservice;
        public FreightController(IUserInfoService s, IFreightService _freightservice) : base(s)
        {
            freightservice = _freightservice;
        }

        /// <summary>
        /// 运费模版
        /// </summary>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole ="10")]
        [HttpGet]
        public ActionResult FreightManage()
        {
            return View();
        }

        /// <summary>
        /// 运费模版分页数据
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "10")]
        [HttpPost]
        public ActionResult GetFreightManage(BaseSearchModel search)
        {
            int total = 0;
            var list = freightservice.GetFreightManage(search, out total);
            return Json(new { Total = total, Results = list });
        }

        /// <summary>
        /// 删除运费模版
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "10")]
        [HttpPost]
        public ActionResult DelFreight(int Id)
        {
            return Json(freightservice.DelFreight(Id, CurrentLoginUser.Id));
        }

        /// <summary>
        /// 删除子项
        /// </summary>
        /// <param name="DetailId"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "10")]
        [HttpPost]
        public ActionResult DelFreightDetail(int DetailId)
        {
            return Json(freightservice.DelFreightDetail(DetailId, CurrentLoginUser.Id));
        }

        /// <summary>
        /// 新增、编辑保存方法
        /// </summary>
        /// <param name="Freight"></param>
        /// <param name="FreightDetail"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "10")]
        [HttpPost]
        public ActionResult EditFreightSubmit(FreightSave Freight, List<FreightDetailSave> FreightDetail)
        {
            return Json(freightservice.EditFreightSubmit(Freight, FreightDetail, CurrentLoginUser.Id));
        }

        /// <summary>
        /// 新增、编辑页数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [AuthorizeFilter(MenuRole = "10")]
        [HttpPost]
        public ActionResult EditFreight(int Id)
        {
            return Json(freightservice.EditFreight(Id));
        }


    }
}